package servlet;

import java.io.IOException;

import jakarta.servlet.Servlet;
import jakarta.servlet.ServletConfig;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import utils.JDBCUtil;

public class DBServlet implements Servlet
{

	@Override
	public void init(ServletConfig config) throws ServletException
	{
		System.out.println(this.toString() + ".init");
		
		String db_url = config.getInitParameter("db_url");
		String db_username = config.getInitParameter("db_username");
		String db_password = config.getInitParameter("db_password");
		
		System.out.println("\nDB_URL: " + db_url);
		System.out.println("DB_USERNAME: " + db_username);
		System.out.println("DB_PASSWORD: " + db_password);
		System.out.println();
		
		JDBCUtil.registerDriver();
		JDBCUtil.init(db_url, db_username,db_password);
		System.out.println();
		
	}

	@Override
	public ServletConfig getServletConfig()
	{
		return null;
	}

	@Override
	public void service(ServletRequest request, ServletResponse response)
			throws ServletException, IOException
	{
		System.out.println(this.getClass().getName() + ".service");
	}

	@Override
	public String getServletInfo()
	{
		return null;
	}

	@Override
	public void destroy()
	{
		System.out.println(this.toString() + ".destroy");
		JDBCUtil.closeConnection();
	}
	

}




